//
//  Md5Apiway.m
//  Experss
//
//  Created by 嗯，大葱 on 17/9/5.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "Md5Apiway.h"

@implementation Md5Apiway

+ (NSString *)getMD5data:(NSString *)userId {
    NSString *str1  = [NSString stringWithFormat:@"%@%@",userId,@"baishiht"];
    NSString *result = [self md25:str1];//第一次加密
    //获取当前的时间戳
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[dat timeIntervalSince1970];
    NSString *timeString = [NSString stringWithFormat:@"%f", a];//转为字符型
    
    NSString *str2 = [NSString stringWithFormat:@"%@%@%ld",result,@"900",[timeString integerValue]+900];
    NSString *result2 = [self md25:str2];
    NSString *tempStr = [NSString stringWithFormat:@"%@.%@.%ld",result2,@"900",[timeString integerValue]+900];
    
    return tempStr;
}

+ (NSString *) md25:(NSString *) input {
    const char *cStr = [input UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
    NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        
        [output appendFormat:@"%02x", digest[i]];
    return  output;
    
}
@end
